
package com.zsrt.day20170407.homework;

import java.util.Scanner;

import org.junit.Test;

/**
 * 输入一个不大于5位的正整数，然后判断它是几位数，打印出各位数，并逆序输出这个整数。
 * @author jmj
 * @date 2017年4月6日
 * @time 下午12:06:41
 */
public class Nixu {
	
	@Test
	public void nixuTest() throws Exception {
		nixu();
	}
	
	/**
	 * 逆序
	 */
	public void nixu(){
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入一个不大于五位的正整数：");
		int num = sc.nextInt();
		sc.close();
		if(num >=1 && num <=99999){
			System.out.println("您输入的数字是正确的。");
		}else{
			System.out.println("您输入的数字有误。");
		}
		if(num >=1 && num <10){
			System.out.println("您输入的数字是1位数" + num);
		}else if(num >=10 && num <100){
			System.out.println("您输入的数字是2位数");
			int shi  = num/10;
			int ge   = num%10;
			int nixu = shi + ge*10;
			System.out.println("十位数是：" + shi);
			System.out.println("个位数是：" + ge);
			System.out.println("逆序所得结果为：" + nixu);	
		}else if(num >=100 && num <1000){
			System.out.println("您输入的数字是3位数");
		    int shi = num/10%10;
		    int bai = num/100;
		    int ge  = num%10;
		    int nixu= shi*10 + ge*100 + bai;
		    System.out.println("百位数是：" + bai);
		    System.out.println("十位数是：" + shi);
		    System.out.println("个位数是：" + ge);
		    System.out.println("逆序所得结果为:" + nixu);
		
		}else if(num >=1000 && num <10000){
			System.out.println("您输入的数字是4位数");
			int qian = num/1000;
			int bai  = num/100%10;
			int shi  = num/10%10;
			int ge   = num%10;
			int nixu = qian + bai*10 + shi*100 + ge*1000;
			System.out.println("千位数是：" + qian);
			System.out.println("百位数是：" + bai);
			System.out.println("十位数是：" + shi);
			System.out.println("个位数是：" + ge);
			System.out.println("逆序所得结果是：" + nixu);	
		}else if(num >=10000 && num <=99999){
			System.out.println("您输入的数字是5位数");
			int wan  = num/10000;
			int qian = num/1000%10;
			int bai  = num/100%10;
			int shi  = num/10%10;
			int ge   = num%10;
			int nixu = qian*10 + bai*100 + shi*1000 + ge*10000 + wan;
			System.out.println("万位数是：" + wan);
			System.out.println("千位数是：" + qian);
			System.out.println("百位数是：" + bai);
			System.out.println("十位数是：" + shi);
			System.out.println("个位数是：" + ge);
			System.out.println("逆序所得结果是：" + nixu);
		}		
		
	}
}
